package com.siwei.mes.controller.system;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.Equipment;
import com.siwei.mes.service.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 设备表相关
 *
 * @author linzi
 * @since 2023-11-25 22:22:21
 */
@Api(value = "设备表")
@RestController
@RequestMapping("equipment")
public class EquipmentController {
    @Resource
    private EquipmentService equipmentService;

    @ApiOperation(value = "新增设备表")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) Equipment entity) {
        return Json.succ().data(ApiResult.addColumn("id", equipmentService.create(entity)));
    }

    @ApiOperation(value = "修改设备表")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) Equipment entity) {
        equipmentService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除设备表")
    @PostMapping("/delete")
    public Json delete(@RequestBody Equipment entity) {
        equipmentService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取设备表")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<Equipment, Equipment> query) {
        return Json.succ().data(equipmentService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取设备表")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(equipmentService.loadById(id));
    }

    @ApiOperation(value = "获取所有设备表")
    @PostMapping("getAll")
    public Json getAll(@RequestBody Equipment entity) {
        return Json.succ().data(ApiResult.addList(equipmentService.getAll(entity)));
    }

    /**
     * @param testProjectType
     * @return
     */
    @ApiOperation(value = "获取对应类型的设备信息")
    @GetMapping("getEquipmentInfo")
    public Json getEquipmentInfo(@RequestParam("testProjectType") String testProjectType) {
        return Json.succ().data(ApiResult.addList(equipmentService.getEquipmentInfo(testProjectType)));
    }

}
